﻿using System;
using System.Net;
using System.Net.Sockets;

namespace Anchor.Sockets
{
    class SocketListener
    {
        public void Invoke()
        {
            Socket MainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint IPEP = new IPEndPoint(IPAddress.Any, Environment.Configuration.TryParseInt32("socket.port"));
            MainSocket.Bind(IPEP);
            MainSocket.Listen(5);

            Console.WriteLine("Listening on port {0}\n\nWaiting for clients...", Environment.Configuration.TryParseInt32("socket.port"));

            MainSocket.BeginAccept(new AsyncCallback(new SocketAccept().CallAccept), MainSocket);
        }
    }
}
